package aiowang.javaprimary.workqueues;

import aiowang.javaprimary.utils.RabbitMqUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Copyright (C), 2017-2021, aiowang
 * Author: aiowang
 * Date: 2021/8/25 16:27
 * FileName: Producer
 * Description:
 */
public class Producer {

    public static final String QUEUE_NAME= "myworkqueue";

    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        //获取连接和通道
        Connection connection = RabbitMqUtils.getConnection();
        Channel channel = connection.createChannel();
        //声明队列
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        String message = "";
        for (int i = 0; i < 100; i++) {
            message = "" + i;
            channel.basicPublish("",QUEUE_NAME, null, message.getBytes());
            Thread.sleep(i);
        }
        channel.close();
        connection.close();
    }


}
